<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Happy dong
 * Created Time: 2019-08-13 14:13
 *
 * Version: 2.0
 */

namespace App\Modules\System\Criterias;


use Flower\Core\Repository\Contracts\RepositoryInterface;
use Flower\Core\Repository\Criterias\BaseCriterias;

class getRoleAuthRuleListCriteria extends BaseCriterias
{
	private $roleId;
	public function __construct($roleId=null)
	{
		$this->roleId = $roleId;
	}

	public function apply($model, RepositoryInterface $repository)
	{
		$roleIds = empty($this->roleId) ? null : $this->roleId;
		return $model
			->when(isset($this->roleId),function($query) use ($roleIds){
				$query->whereIn('role_id',$roleIds);
			})
			->orderBy('role_id','asc');
	}
}